package com.jinlia.show.modules.openservice.controller;

import com.alibaba.fastjson.JSONObject;
import com.jinlia.show.modules.openservice.service.AliyunSmsService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("aliyun/sms")
public class AliyunSmsController {

    final AliyunSmsService aliyunSmsService;
    @Value("${aliyun.sms.sign-name-blog}")
    public String signNameBlog;//文件访问路径

    @Value("${aliyun.sms.template-code-blog}")
    public String templateCodeBlog;//文件访问路径

    @GetMapping("{code}/{phone}")
    public ResponseEntity getPage(@PathVariable("code") String code, @PathVariable("phone") String phone) {
        JSONObject templateParam = new JSONObject();
        templateParam.put("code", code);
        aliyunSmsService.sendSms(signNameBlog, templateCodeBlog, phone, templateParam.toString());
        return ResponseEntity.ok(Boolean.TRUE);
    }

}
